<?php

/*

Nursery (nursery.pro.php)

*/
ob_start();
$rank_check = 1;
$page_title = "Nursery";
include "global.inc.php";

$findPet    = fetch("SELECT id FROM user_pets2 WHERE owner = '$userid' AND adoption = '0' AND id = '$pet_name'");
if (!$findPet[id])
{
	die(header(error("nursery.php?game=$game", "That pet is not yours.")));
}

$findItem   = fetch("SELECT id,item_id,parts_left FROM usersitems2 WHERE owner = '$userid' AND id = '$item_name'");
if (!$findItem[id])
{
	die(header(error("nursery.php?game=$game", "That item is not yours.")));
}

$getItem    = fetch("SELECT id,item_name,item_type FROM items2 WHERE id = '$findItem[item_id]'");
if (($getItem[item_type] != "food") AND ($getItem[item_type] != "toy"))
{
	die(header(error("nursery.php?game=$game", "You can only use toys and food items.")));
}

if ($getItem[item_type] == "food") { $item_type = 1; }
if ($getItem[item_type] == "toy") { $item_type = 2; }

if ($feed_time == "minutes")
{
	$feedAt = $timestamp + ($feed_number * 60);
}

if ($feed_time == "hours")
{
	$feedAt = $timestamp + ($feed_number * 3600);
}

if ($feed_time == "days")
{
	$feedAt = $timestamp + ($feed_number * 86400);
}

mysql_query("INSERT INTO pet_feeder VALUES ('', '$getItem[id]', '$userid', '$findPet[id]', '$findItem[parts_left]', '$feedAt', '$game', '$item_type')");
mysql_query("DELETE FROM usersitems2 WHERE owner = '$userid' AND id = '$item_name'");

points($game,"$username",-15);

die(header(error("nursery.php?game=$game", "Your item has been scheduled!")));
?>